import Vue from "vue";
import Vuex from "vuex";

import createPersistedState from "vuex-persistedstate";
import {setItem,getItem} from '../utils/storage'


Vue.use(Vuex);


const TOKEN_KEY = 'FILM_USER'

export default new Vuex.Store({
  plugins: [createPersistedState()],
  modules: {},
  state: {
    cityName: "北京",
    cityId: "110100",
    isLogin: false,
    isSelectCity: false,
    // 存储用户信息
    user:getItem(TOKEN_KEY)
  },
  mutations: {
    changeCityName(state, value) {
      state.cityName = value;
    },
    changeCityId(state, value) {
      state.cityId = value;
    },
    changeLogin(state, value) {
      state.isLogin = value;
    },
    changeSelectCity(state, value) {
      state.isSelectCity = value;
    },
    // 存储用户数据
    setUser(state,data){
      state.user = data
      setItem(TOKEN_KEY,state.user)
    }
  },
  actions: {},
  getters: {}
});
